package com.xiaozhou.leetCode.leetCode100;

import java.math.BigDecimal;

public class LeetCode5 {

    private BigDecimal min;



    public static String longestPalindrome(String s) {
        if (s == null || s.length() == 0){
            return "";
        }
        if (s.length() == 1){
            return s;
        }
        int maxNum = 1;
        int begin = 0;
        boolean[][] dp = new boolean[s.length()][s.length()];
        // 计算自己长短的 如果是自己肯定是回文
        for (int i = 0; i < s.length(); i++) {
            dp[i][i] = true;
        }
        for (int l = 2; l<= s.length(); l++) {

            for (int i = 0; i< s.length(); i++) {
                int j = i + l - 1;
                if (j >= s.length()){
                    break;
                }
                if (s.charAt(i) != s.charAt(j)){
                    dp[i][j] = false;
                }else {
                    if (j - i < 3){
                        dp[i][j] = true;
                    }else {
                        dp[i][j] = dp[i + 1][j - 1];
                    }
                }

                if (dp[i][j] && j - i + 1 > maxNum){
                    maxNum = j - i + 1;
                    begin = i;
                }
            }
        }
        return s.substring(begin, begin + maxNum);
    }

    public static void main(String[] args) {
        String babad = longestPalindrome("bb");
        System.out.println(babad);
        BigDecimal bigDecimal = BigDecimal.valueOf(0.000).setScale(3);
        LeetCode5 leetCode5 = new LeetCode5();
        leetCode5.setMin(bigDecimal);
        System.out.println(bigDecimal);
        System.out.println(leetCode5);
    }

    public BigDecimal getMin() {
        return min;
    }

    public void setMin(BigDecimal min) {
        this.min = min;
    }
}
